//
//  ViewController.m
//  HWanGame
//
//  Created by Chendaobin on 2019/8/23.
//  Copyright © 2019年 Chendaobin. All rights reserved.
//

#import "ViewController.h"
#import "HWTabBarController.h"
#import <CYLTabBarController.h>
#import <AdSupport/AdSupport.h>

#import <AppTrackingTransparency/AppTrackingTransparency.h>

#import <AdSupport/ASIdentifierManager.h>

@interface ViewController ()
@property(strong,nonatomic) UIImageView *icoimage;
@property(strong,nonatomic) NSDictionary *dataDic;
@property(strong,nonatomic) UIView *baiseView;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [self addtupian];
    [self fasongwangluoqing];
    
    NSTimer* timer = [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(Timered:) userInfo:nil repeats:NO];
    
    
    
    // 商品详情
    
    
    //  pod 'AFNetworking', '~> 3.2.1'
    
    
    //    NSArray *arr = @[@"2",@"7",@"11",@"9"];
    //      NSInteger target = 9 ;
    //
    //
    //      for (int i = 0 ; i < arr.count; i++) {
    //
    //          for (int  j =  i + 1  ; j < arr.count ; j ++  ) {
    //              NSLog(@" i :%d ----- j : %d",i,j);
    //
    //          }
    //
    //      }
    //
    
    self.baiseView = [[UIView alloc] initWithFrame:CGRectMake(0, kScreenH-158, kScreenW, 158)];
    self.baiseView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview: self.baiseView];
    
    UIImageView * tubiaoico = [[UIImageView alloc]initWithFrame:CGRectMake((kScreenW -38)/2 ,55 , 38 ,38 )];
    tubiaoico.layer.cornerRadius = 10 ;
    tubiaoico.layer.masksToBounds = YES;
    [self.baiseView  addSubview:tubiaoico];
    
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, tubiaoico.bottom+7, kScreenW-20 , 22)];
    //  label.backgroundColor = RGB(255, 217, 161);
    //   label.layer.cornerRadius = 32;
    //     label.layer.masksToBounds = YES;
    label.textColor = RGB(51, 51, 51);
    label.textAlignment = NSTextAlignmentCenter;
    label.font = [UIFont boldSystemFontOfSize:16];
    //  label.text = @"iijviijf";
    [self.baiseView addSubview:label];
    
    NSDictionary *dic =  [[NSBundle mainBundle] infoDictionary];
    //        NSString *icostr =     dic[@"CFBundleIcons"][@"CFBundlePrimaryIcon"][@"CFBundleIconName"];
    //UIImage *appIcon = [UIImage imageNamed: [[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIcons"] objectAtIndex:0]];
    UIImage  *appIcon = [UIImage imageNamed:@"AppIcon"];
    tubiaoico.image = appIcon ;
    
    tubiaoico.layer.cornerRadius = 10 ;
    tubiaoico.layer.masksToBounds = YES;
    label.text = [NSString stringWithFormat:@"%@",dic[@"CFBundleDisplayName"]];
    
    
    
    
    
}

- (void)Timered:(NSTimer*)timer {
    NSLog(@"timer called");
//    [HWTabBarPlusButton registerPlusButton];
    HWTabBarController1 *control = [[HWTabBarController1 alloc] initWithViewControllers:[HWTabBarConfig controllers] tabBarItemsAttributes:[HWTabBarConfig tabBarItemsAttributesForController]];
    //    HWTabBarController1 *control = [[HWTabBarController1 alloc] init];
    kKeyWindow.rootViewController = control;
    
    
}


- (void)addtupian {
    
    self.icoimage  = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH-158)];
    self.icoimage.backgroundColor = [UIColor whiteColor];
    // self.icoimage.image = [UIImage imageNamed:@"lanuch_bg"];
    self.icoimage.contentMode  = UIViewContentModeScaleAspectFill;
    
    [self.view addSubview:self.icoimage];
    
    //
    // /Users/chendaobin/app/flutter/bin
    
    
}


- (void)fasongwangluoqing {
    HWTabBarController *control = [[HWTabBarController alloc] init];
    NSDictionary *parameters = @{
        @"ct" : @"app",
        @"ac" : @"welcome",
        @"member_id":[HWLocallyStoredData getCode]
    };
    [HWWebUtils doGetWithParameters:parameters progress:nil success:^(id response) {
        [SVProgressHUD dismiss];
        if ([response[@"code"] intValue] == 1) {
            
            //  [self.window setRootViewController:control];
            self.dataDic = response[@"data"];
            NSString *icostr  = [NSString stringWithFormat:@"%@", self.dataDic[@"image"]];
            NSURL *URL = [NSURL URLWithString:icostr];
            [self.icoimage sd_setImageWithURL:URL placeholderImage:nil];
            
            
            
            
            
            
        } else {
            
            
            kKeyWindow.rootViewController = control;
        }
        //        [self.window setRootViewController:control];
        
    } failure:^(NSString *error) {
        
        //  [SVProgressHUD dismiss];
        
    }];
    
    
    
}





@end
